/*
 * httphandlefoundfile.cpp
 *
 *  Created on: Apr 27, 2009
 *      Author: kuncai
 */
#ifndef HTTPHANDLEFOUNDFILE_H_
#define HTTPHANDLEFOUNDFILE_H_
#include <fstream>
using namespace std;
#include "log.h"
#include "httphandle.h"
#include "date.h"
using namespace Http;
class HttpHandleFoundFile: public HttpHandle{
	void ProcessRequest(HttpRequest* httpRequest, HttpResponse* httpResponse){
		//base http msg
		Date now;
		httpResponse->SetHeader(Http::Dates,now.ToString().c_str() );
		httpResponse->SetHeader(Http::Server,"Xpie 1.0");
		//read url file
		string sFilename = "."+httpRequest->GetParam("url"); 
		string htmlstr="";
		string tempstr="";
		ifstream fin(sFilename.c_str(), std::ios::in);
		if(fin){
			//open file success
			/*
			while(getline(fin,tempstr)){
				htmlstr += tempstr;
				Log::Debug("tempstr:   %s\n",tempstr.c_str());
			}
			fin.close();
			httpResponse->SetStatus("200");
			httpResponse->SetReason("OK");
			httpResponse->SetContent(htmlstr);
			*/
			fin.close();
			if(successor != NULL){
				successor->ProcessRequest(httpRequest, httpResponse);
			}
		}else{
			//open file fail
			httpResponse->SetStatus("404");
			httpResponse->SetReason("Not Found");
			if(error != NULL){
				error->ProcessRequest(httpRequest, httpResponse);
			}
		}
		//end read url file

	}
};
#endif /* HTTPHANDLEFOUNDFILE_H_ */
